package hp.com.service.impl;

import hp.com.dao.UsersDAO;
import hp.com.dao.impl.UsersDAOImpl;
import hp.com.entity.Users;
import hp.com.service.UsersService;

import java.sql.SQLException;

public class UsersServiceImpl implements UsersService {
    private UsersDAO usersDAO = new UsersDAOImpl();
    //用户注册
    @Override
    public boolean addUsers(Users users) throws Exception {
        int i = usersDAO.addUsers(users);
        if(i>0){
            return true;
        }else {
            return false;
        }
    }
    private UsersDAO dao = new UsersDAOImpl();

    @Override
    public boolean UsersById(Users users) throws Exception {
        return dao.UsersById(users);
    }

    @Override
    public Users checkPhone(Users users) throws Exception {
        return usersDAO.checkPhone(users);
    }

    // 验证用户修改时手机号是否输入正确
    @Override
    public boolean checkOldPhone(Users users) throws Exception {
        return usersDAO.checkOldPhone(users);
    }

    // 验证手机号是否被其它用户注册
    @Override
    public boolean checkNewPhone(Users users) throws Exception {
        return usersDAO.checkNewPhone(users);
    }

    // 用户修改手机号
    @Override
    public boolean updateUserPhone(Users users) throws Exception {
        int i = usersDAO.updateUserPhone(users);
        if (i>0){
            return true;
        }else {
            return false;
        }
    }

    // 验证用户修改时邮箱是否输入正确
    @Override
    public boolean checkOldEmail(Users users) throws Exception {
        return usersDAO.checkOldEmail(users);
    }

    // 用户修改邮箱
    @Override
    public boolean updateUserEmail(Users users) throws Exception {
        int i = usersDAO.updateUserEmail(users);
        if (i>0){
            return true;
        }else {
            return false;
        }
    }

    // 验证用户修改时原密码是否输入正确
    @Override
    public boolean checkOldPwd(Users users) throws Exception {
        return usersDAO.checkOldPwd(users);
    }

    @Override
    public Users GetUserById(int ID) throws Exception {
        return usersDAO.getUserByID(ID);
    }

    // 通过id进行密码修改
    @Override
    public boolean updateUsersPwd(Users users) throws Exception {
        int i = usersDAO.updateUsersPwd(users);
        if (i>0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean checkPhoneValid(String phone) throws Exception {
        return dao.checkPhoneValid(phone);
    }
}
